<template>
  <tr>
    <th>
      <input type="checkbox" @change="setcheck" :checked="item.checked"/>
    </th>
    <th>{{item.name}}</th>
    <th>{{item.price}}</th>
    <th><button @click="subnum(item.num)">-</button> {{item.num}} <button @click="addnum">+</button></th>
    <th>{{item.price*item.num}}</th>
    <th><button @click="removeitem">删除</button></th>
  </tr>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  props: {
    item: {
      type: Object
    },
    index: {
      type: Number
    }
  },
  data () {
    return {}
  },
  created () {},

  methods: {
    ...mapMutations(['subNum', 'addNum', 'removeItem', 'setCheck']),
    subnum (i) {
      if (i <= 1) return alert('数量不能小于1')
      this.subNum(this.index)
    },
    addnum () {
      this.addNum(this.index)
    },
    removeitem () {
      this.removeItem(this.index)
    },
    setcheck () {
      this.setCheck(this.index)
    }
  }
}
</script>

<style scoped lang="less"></style>
